package org.goldenport.g3.app

import org.goldenport.g3._
import org.goldenport.g3.atom._
import org.goldenport.g3.messages._
import org.goldenport.g3.messages.http._
import org.goldenport.g3.events.Getted

/**
 * @since   Nov. 28, 2010
 * @version Nov. 29, 2010
 * @author  ASAMI, Tomoharu
 */
class Html5Service extends G3Application with UseRecord {
  port("/") html(<p>OK</p>)

  port("/sse") agent {
    case _ => {
      println("via /sse")
      EventStream(System.currentTimeMillis.toString, 1000)
    }
  }

  port("/ws/chat") agent {
    case msg: Post => {
      println("ws = " + msg)
      new Post("/chat", msg.content)
    }
  } invoke("wschat")

  websocket('wschat, "/chat")
  websocket('wstimer, "/timer")

  timer("") agent {
    case msg: Post => {
      println("timer in Html5Service")
      Post("/timer", "Time: " + System.currentTimeMillis)
    }
  } invoke("wstimer")
}
